package com.huatai.datacenter.controller.feignapi;

import com.huatai.common.api.R;
import com.huatai.datacenter.entity.PutSingle;
import com.huatai.datacenter.feign.TSDBPutClient;
import com.huatai.datacenter.service.PutService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @program: ht-system
 * @description: TSDB写入
 * @author: songxiude
 * @create: 2023-04-25 14:50
 **/
@RestController
@AllArgsConstructor
@Api(value = "opentsdb-写入", tags = "opentsdb-写入")
public class TSDBPutApiController implements TSDBPutClient {

	private final PutService putService;

	/**
	 * 同步写入
	 *
	 * @param putSingle 单个写入参数
	 * @return 写入结果
	 */
	@Override
	@PostMapping(SINGLE)
	@ApiOperation(value = "单设备标签同步写入", notes = "putSingle")
	public R<Object> syncPut(@RequestBody PutSingle putSingle) {
		return R.data(putService.syncPut(putSingle));
	}

	/**
	 * 同步写入
	 *
	 * @param putSingles 单个写入参数
	 * @return 写入结果
	 */
	@Override
	@PostMapping(MULTIPLE)
	@ApiOperation(value = "多设备标签同步写入", notes = "putSingles")
	public R<Boolean> syncPut(@Valid @RequestBody List<PutSingle> putSingles) {
		return R.status(putService.syncPutList(putSingles));
	}

	/**
	 * 异步写入
	 *
	 * @param putSingle 单个写入参数
	 */
	@Override
	@PostMapping(ASYNC_SINGLE)
	@ApiOperation(value = "单设备标签异步写入", notes = "putSingle")
	public void asyncPut(@Valid @RequestBody PutSingle putSingle) {
		putService.asyncPut(putSingle);
	}

	/**
	 * 同步写入
	 *
	 * @param putSingles 单个写入参数
	 */
	@Override
	@PostMapping(ASYNC_MULTIPLE)
	@ApiOperation(value = "多设备标签异步写入", notes = "putSingles")
	public void asyncPutList(@Valid @RequestBody List<PutSingle> putSingles) {
		putService.asyncPutList(putSingles);
	}


	/**
	 * 同步写入
	 *
	 * @param putSingles 单个写入参数
	 */
	@Override
	@PostMapping(SYNC_PUT_DIFFERENCE)
	@ApiOperation(value = "单设备写入插值计算", notes = "单设备写入插值计算")
	public R<Object> syncPutDifference(@RequestBody PutSingle putSingles) {
		putSingles.setDifference(true);
		Boolean result = putService.syncPutDifference(putSingles);
		return R.data(result);
	}

}

